﻿@page "/customization/globals"

<DocsPage>
    <DocsPageHeader Title="Globals" SubTitle="Static properties that let you control the default behavior of some parts of MudBlazor.">
        <Description>
            <DocsPageSection>
                <MudAlert Class="mt-4" Severity="Severity.Error">
                    <b>EXPERIMENTAL:</b>
                    This feature is under development and may not be ready for general use.
                    Breaking changes <b>will occur</b> between releases.  
                    Use only if you are prepared to adapt your code and <MudLink Typo="Typo.inherit" Href="https://github.com/MudBlazor/MudBlazor/issues/new/choose">provide feedback</MudLink> or <MudLink Typo="Typo.inherit" Href="https://github.com/MudBlazor/MudBlazor/blob/dev/src/MudBlazor/Services/MudGlobal.cs">contribute to its development</MudLink>.
                </MudAlert>
            </DocsPageSection>
        </Description>
    </DocsPageHeader>
    <DocsPageContent>
        <DocsPageSection>
            <SectionHeader Title="Usage">
                <Description>
                    You can find default setting overrides of some MudBlazor features in the static <ApiTypeLink TypeName="MudGlobal" /> class.
                    These defaults should be set when your application initializes, such as when adding MudBlazor services.
                    If they are set after the app has started, they may not take effect until the next page load, or may not take effect at all.
                    
                    <MudAlert Class="mt-4" Severity="Severity.Info">
                        Our theming system is recommended for changing the looks and style of your application.
                        To find more ways to customize your app, refer to our other documentation in the sidebar.
                    </MudAlert>
                </Description>
            </SectionHeader>
        </DocsPageSection>

        <DocsPageSection>
            <SectionHeader Title="Exception Handler">
                <Description>
                    You can handle MudBlazor component exceptions using <CodeInline>MudGlobal.UnhandledExceptionHandler</CodeInline>.
                </Description>
            </SectionHeader>
            <SectionContent Code="@nameof(GlobalExceptionHandlerExample)" />
        </DocsPageSection>
    </DocsPageContent>
</DocsPage>

@code
{
    private List<DocumentedType> TypesWithGlobals { get; set; }

    protected override void OnInitialized()
    {
        // Find the types which have global settings
        TypesWithGlobals = [.. ApiDocumentation.Types.Where(pair => pair.Value.GlobalSettings.Count > 0).Select(pair => pair.Value).OrderBy(type => type.NameFriendly)];
        base.OnInitialized();
    }
}
